package com.test.beanPostProcessor;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.core.PriorityOrdered;
import org.springframework.stereotype.Component;

/**
 * 一开始,我的test跑起来没反映,错误原因
 * 1.没有加@Component
 * 2.config.class中@ComponentScan没有扫描到这包
 */
@Component
public class MyFirstBeanPostProcessor implements BeanPostProcessor, PriorityOrdered {
	@Override
	public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
		if ("myFactoryBeanOrMyObject".equals(beanName)) {
			System.out.println("postProcess_BeforeInitialization..");
		}
		return bean;
	}

	@Override
	public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
		if ("myFactoryBeanOrMyObject".equals(beanName)) {
			System.out.println("postProcess_AfterInitialization..");
		}
		return bean;
	}

	/**
	 * 越小越早
	 * @return
	 */
	@Override
	public int getOrder() {
		return 99;
	}
}
